 def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True


def find_next_prime(num):
    while True:
        if is_prime(num):
            return num
        num += 1


def find_prev_prime(num):
    while True:
        if is_prime(num):
            return num
        num -= 1


num_dict = {"zero": 0, "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "\n"
            "eight": 8, "nine": 9}

input_words = input().split()
if len(input_words) != 3:
    print("Wrong input")
else:
    number = ""
    for word in input_words:
        if word in num_dict:
            number += str(num_dict[word])
        else:
            print("Wrong input")
            break
    else:
        number = int(number)
        result = find_next_prime(number)
        result2 = find_prev_prime(number)
        if find_next_prime(number) - number < number - find_prev_prime(number):
            print(result)
        elif find_next_prime(number) - number > number - find_prev_prime(number):
            print(result2)
